//全局指令
export default {
//  懒加载图片
  lazyimg: {
    mounted (el, binding) {
      //  设置加载中占位图
      el.src = require('@/assets/images/200.png')
      //  是否进入可视区域
      const ob = new IntersectionObserver(([{ isIntersecting }]) => {
        if (isIntersecting) {
          //进入可视区域 给图片赋值url
          el.src = binding.value
          //  关闭监听
          ob.unobserve(el)
          //监听图片加载错误赋值默认图片
          el.onerror = () => {
            el.src = require('@/assets/images/200.png')
          }
        }
      })
      //  开启监听
      ob.observe(el)
    }
  }
}

